<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :href="symbolId" />
  </svg>
</template>

<script lang="ts" setup>
import { withDefaults, computed } from "vue";

interface propInterface {
  prefix?: string;
  className?: string;
  name: string;
}
const props = withDefaults(defineProps<propInterface>(), {
  prefix: "icon",
  name: "svgIcon",
  className: "",
});
const symbolId = computed(() => `#${props.prefix}-${props.name}`);
const svgClass = computed(() => {
  if (props.className) {
    return `svg-icon ${props.className}`;
  }
  return "svg-icon";
});
</script>
<style scope>
.svg-icon {
  width: 1em;
  height: 1em;
  /* 因icon大小被设置为和字体大小一致，而span等标签的下边缘会和字体的基线对齐，故需设置一个往下的偏移比例，来纠正视觉上的未对齐效果 */
  vertical-align: -0.1em;
  /* 定义元素的颜色，currentColor是一个变量，这个变量的值就表示当前元素的color值，如果当前元素未设置color值，则从父元素继承 */
  fill: currentColor;
  overflow: hidden;
}
</style>
